/*************************************************************************************
 *
 *  Revolution Engine
 *  Copyright (C) 2009 Felipe Apablaza
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License as published by the Free Software Foundation; either
 *  version 2.1 of the License, or (at your option) any later version.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 ************************************************************************************/


//---------------------------------------------------------
//
//  File:	IThread.hpp
//  Desc:	Contain the IThread interface. 
//
//---------------------------------------------------------

#ifndef __REVENG_ITHREAD_HPP__
#define __REVENG_ITHREAD_HPP__

#include <RevEng/Config.h>
#include <RevEng/DataTypes.hpp>
#include <RevEng/IObject.hpp>
#include <typeinfo>

#define REVENG_THREAD			0x0000C000

//Thread states
#define REVENG_THREAD_READY		0x0000C001	//Thread ready to be executed
#define REVENG_THREAD_RUNNING	0x0000C002	//Thread already executing

namespace RevEng
{
	class IObject;

	//The Thread class will execute IThreaded::Run method in a separate 
	//flow of code.
	class IThreaded
	{
	public:
		virtual Int32 Run(void* Param) throw() = 0;
	};
	
	
	//IThread Class.
	//Execute parallel code.
	class __REVENG_EXPORT__ IThread : public IObject
	{
	public:
		virtual ~IThread() = 0;
		
		virtual Enum GetClassId() const;

		virtual void Start(void* Param) = 0;
		virtual void Wait() = 0;
		virtual void Abort() = 0;
		virtual Enum GetStatus() const = 0;

		virtual void SetThreaded(IThreaded* Threaded) = 0;
		virtual Int32 GetExitCode() const = 0;

	public:
		static void Yield();
		static void Sleep(Double secs);
	};


	inline IThread::~IThread()
	{
	}

	inline Enum IThread::GetClassId() const
	{
		return REVENG_THREAD;
	}
}

#endif	//__REVENG_IMPL_ITHREAD_HPP__
